import { configureStore } from "@reduxjs/toolkit";
import homeReducer from "./modules/home";

import {
  useSelector,
  useDispatch,
  TypedUseSelectorHook,
  shallowEqual,
} from "react-redux";

const store = configureStore({
  reducer: {
    home: homeReducer,
  },
  // 默认启用 react dev-tools
  devTools: true,
});

type GetStateFnType = typeof store.getState;
// 获取store中的state类型
export type IRootStateType = ReturnType<GetStateFnType>;

// useAppSelector的hook
export const useAppSelector: TypedUseSelectorHook<IRootStateType> = useSelector;
type DispatchType = typeof store.dispatch;
export const useAppDispatch: () => DispatchType = useDispatch;
export const shallowEqualApp = shallowEqual;

export default store;
